/*
 *  Date: 2011-11-6 下午04:00:49
 *  Copyright (c) 2011 asiainfo-linkage
 */
package com.gjframe.example.service.impl;

import com.gjframe.commen.db.model.Condition;
import com.gjframe.commen.db.provider.annotation.TxSupport;
import com.gjframe.commen.db.provider.helper.Pagination;
import com.gjframe.commen.helper.StringUtils;
import com.gjframe.example.bean.BasePerson;
import com.gjframe.example.dao.PersonDAO;
import com.gjframe.example.service.PersonService;

public class PersonServiceImpl implements PersonService {

    private PersonDAO personDao;

    public Pagination<BasePerson> findList(BasePerson person, Integer pageNo, Integer pageSize) throws Exception {
        Condition cond = new Condition();
        if (person != null) {
            if (!StringUtils.isEmpty(person.getName())) {
                cond.and(" name like :name").set("name", "%" + person.getName() + "%");
            }
            if (!StringUtils.isEmpty(person.getTel())) {
                cond.and(" tel=:tel").set("tel", person.getTel());
            }
        }
        return personDao.findList(cond, pageNo, pageSize);
    }
    @TxSupport
    public int update(BasePerson person) throws Exception {
        return personDao.update(person);
    }

    public BasePerson findById(Integer id) throws Exception {
        return personDao.findById(id);
    }

    @TxSupport
    public int save(BasePerson person) throws Exception {
        return personDao.save(person);
    }
    @TxSupport
    public int delete(Integer id)throws Exception{
        return personDao.delete(id);
    }

    public void setPersonDao(PersonDAO personDao) {
        this.personDao = personDao;
    }

    

}
